package jdbc.mysql.gzpowernode;

import java.sql.*;
import java.util.*;

//处理查询结果集
public class test03 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        ResourceBundle rb = ResourceBundle.getBundle("jdbc1");
        String url = rb.getString("url");
        String user = rb.getString("user");
        String password = rb.getString("password");
        String driver = rb.getString("driver");
        String sql = rb.getString("sql");
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            while (rs.next()) {
                String ename = rs.getString("ename");
                int empno = rs.getInt("empno");
                Double sal = rs.getDouble("sal");
                System.out.println(ename + "," + empno + "," + sal);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                    System.out.println("rs has closed!");
                }
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("rs can't close!");

            }
            try {
                if (stmt != null) {
                    stmt.close();
                    System.out.println("stmt has closed!");
                }
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("stmt can't close!");

            }
            try {
                if (conn != null) {
                    conn.close();
                    System.out.println("conn has closed!");
                }
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("conn can't close!");

            }
        }

    }
}